home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MultiSession 1.04 Source / Core 27⁄June⁄1993 / CRadioButton.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-09  |  4.2 KB  |  170 lines  |  [TEXT/KAHL]

  1. /* CRadioButton.c */
  2.  
  3. #include "CRadioButton.h"
  4. #include "CSack.h"
  5. #include "CWindow.h"
  6. #include "Memory.h"
  7.  
  8. /* */            CRadioButton::~CRadioButton()
  9.     {
  10.         CRadioButton*        Temp;
  11.  
  12.         ERROR(Initialized != True,PRERR(ForceAbort,
  13.             "CRadioButton::~CRadioButton called on uninitialized object."));
  14.         ReleaseHandle(Name);
  15.         Temp = this;
  16.         RadioGroup->KillElement(&Temp);
  17.         if (RadioGroup->NumElements() == 0)
  18.             {
  19.                 delete RadioGroup;
  20.             }
  21.     }
  22.  
  23.  
  24. void            CRadioButton::IRadioButton(LongPoint Start, LongPoint Extent,
  25.                         Handle NameString, char Key, short Modifiers, CSack** CurrentRadioGroup,
  26.                         short TheFontID, short ThePointSize, CWindow* TheWindow,
  27.                         CEnclosure* TheEnclosure)
  28.     {
  29.         CRadioButton*    Temp;
  30.  
  31.         ERROR(Initialized == True,PRERR(ForceAbort,
  32.             "CRadioButton::IRadioButton called on already initialized object."));
  33.         EXECUTE(Initialized = True);
  34.         FontID = TheFontID;
  35.         PointSize = ThePointSize;
  36.         Name = NameString;
  37.         ERROR(NameString==NIL,PRERR(ForceAbort,
  38.             "CRadioButton::IRadioButton passed NIL for name."));
  39.         IButton(Start,Extent,Key,Modifiers,TheWindow,TheEnclosure);
  40.         State = False;
  41.         if (*CurrentRadioGroup == NIL)
  42.             {
  43.                 *CurrentRadioGroup = new CSack; /* if this is the first group member, then */
  44.                 (*CurrentRadioGroup)->ISack(sizeof(CRadioButton*),128); /* make new list */
  45.             }
  46.         RadioGroup = *CurrentRadioGroup; /* remember our associates */
  47.         Temp = this;
  48.         RadioGroup->PushElement(&Temp); /* add ourselves to the list */
  49.     }
  50.  
  51.  
  52. void            CRadioButton::RedrawNormal(void)
  53.     {
  54.         long        Top,Left,Right,Bottom;
  55.  
  56.         ERROR(Initialized != True,PRERR(ForceAbort,
  57.             "CRadioButton::RedrawNormal called on uninitialized object."));
  58.         SetUpPort();
  59.         Window->ResetPen();
  60.         if (!Enabled)
  61.             {
  62.                 Window->SetGreyishTextOr();
  63.             }
  64.         Left = 0;
  65.         Top = (Extent.y / 2) - 6;
  66.         Right = 12;
  67.         Bottom = 12;
  68.         Window->LEraseRect(LongPointOf(Left,Top),LongPointOf(Right,Bottom));
  69.         Window->LFrameOval(LongPointOf(Left,Top),LongPointOf(Right,Bottom));
  70.         if (State)
  71.             {
  72.                 Top += 3;
  73.                 Left += 3;
  74.                 Bottom -= 6;
  75.                 Right -= 6;
  76.                 Window->LPaintOval(LongPointOf(Left,Top),LongPointOf(Right,Bottom));
  77.             }
  78.         Window->SetText(FontID,0,srcOr,PointSize,0);
  79.         if (!Enabled)
  80.             {
  81.                 Window->SetGreyishTextOr();
  82.             }
  83.         HLock(Name);
  84.         Window->LTextBox(LongPointOf(12+6,0),LongPointOf(Extent.x-(12+6),Extent.y),
  85.             Name,JustifyLeft);
  86.         HUnlock(Name);
  87.     }
  88.  
  89.  
  90. void            CRadioButton::RedrawHilited(void)
  91.     {
  92.         long        Top,Left,Right,Bottom;
  93.  
  94.         ERROR(Initialized != True,PRERR(ForceAbort,
  95.             "CRadioButton::RedrawHilited called on uninitialized object."));
  96.         SetUpPort();
  97.         Window->ResetPen();
  98.         Left = 0;
  99.         Top = (Extent.y / 2) - 6;
  100.         Right = 12;
  101.         Bottom = 12;
  102.         Window->LEraseRect(LongPointOf(Left,Top),LongPointOf(Right,Bottom));
  103.         Window->LFrameOval(LongPointOf(Left,Top),LongPointOf(Right,Bottom));
  104.         Top += 1;
  105.         Left += 1;
  106.         Right -= 2;
  107.         Bottom -= 2;
  108.         Window->LFrameOval(LongPointOf(Left,Top),LongPointOf(Right,Bottom));
  109.         if (State)
  110.             {
  111.                 Top += 2;
  112.                 Left += 2;
  113.                 Bottom -= 4;
  114.                 Right -= 4;
  115.                 Window->LPaintOval(LongPointOf(Left,Top),LongPointOf(Right,Bottom));
  116.             }
  117.         Window->SetText(FontID,0,srcOr,PointSize,0);
  118.         HLock(Name);
  119.         Window->LTextBox(LongPointOf(12+6,0),LongPointOf(Extent.x-(12+6),Extent.y),Name,JustifyLeft);
  120.         HUnlock(Name);
  121.     }
  122.  
  123.  
  124. MyBoolean    CRadioButton::DoThang(void)
  125.     {
  126.         CRadioButton*    Temp;
  127.  
  128.         ERROR(Initialized != True,PRERR(ForceAbort,
  129.             "CRadioButton::DoThang called on uninitialized object."));
  130.         ERROR(RadioGroup==NIL,PRERR(ForceAbort,
  131.             "CRadioButton::DoThang RadioGroup is NIL."));
  132.         RadioGroup->ResetScan();
  133.         while (RadioGroup->GetNext(&Temp))
  134.             {
  135.                 if (Temp != this)
  136.                     {
  137.                         Temp->Uncheck(); /* implicit Temp->ClearState() call here. */
  138.                     }
  139.             }
  140.         State = True;
  141.         SetState();
  142.         return False;
  143.     }
  144.  
  145.  
  146. void            CRadioButton::Uncheck(void)
  147.     {
  148.         ERROR(Initialized != True,PRERR(ForceAbort,
  149.             "CRadioButton::Uncheck called on uninitialized object."));
  150.         if (State != False)
  151.             {
  152.                 ClearState();
  153.                 State = False;
  154.                 RedrawNormal();
  155.             }
  156.     }
  157.  
  158.  
  159. /* the following two functions are to be overridden to do anything you need to do, such */
  160. /* as maintaining a shared status flag elsewhere.  Note, ClearState always called before */
  161. /* SetState, so that only zero or one, but not more states are ever in effect. */
  162. void            CRadioButton::SetState(void)
  163.     {
  164.     }
  165.  
  166.  
  167. void            CRadioButton::ClearState(void)
  168.     {
  169.     }
  170.